package org.hot100_0.leetcode160;

import org.leetcode.easy.ListNode;

import java.util.HashSet;
import java.util.List;

public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {

        HashSet<ListNode>  hashSet = new HashSet<>( );
        while (headA!=null){
            hashSet.add(headA);
            headA=headA.next;
        }

        while (headB!=null){
            if (hashSet.contains(headB)){
                return headB;
            }

            headB= headB.next;
        }

        return null;
    }
}
